/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.tom.social.dal.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Tom
 */
@Entity
@Table(name = "Owner")
@NamedQueries({@NamedQuery(name = "Owner.findAll", query = "SELECT o FROM Owner o"),
	@NamedQuery(name = "Owner.findByFirstName", query = "SELECT o FROM Owner o WHERE o.firstName = :firstName"),
	@NamedQuery(name = "Owner.findByMiddleName", query = "SELECT o FROM Owner o WHERE o.middleName = :middleName"),
	@NamedQuery(name = "Owner.findByLastName", query = "SELECT o FROM Owner o WHERE o.lastName = :lastName")})
public class Owner implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Basic(optional = false)
	@Column(name = "id")
	private Integer id;
	@Column(name = "firstName")
	private String firstName;
	@Column(name = "middleName")
	private String middleName;
	@Column(name = "lastName")
	private String lastName;
	@Column(name = "birthDate")
	@Temporal(TemporalType.TIMESTAMP)
	private Date birthDate;
	@JoinTable(name = "Site_Owner", joinColumns = {@JoinColumn(name = "owner_id", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "site_id", referencedColumnName = "id")})
	@ManyToMany(fetch=FetchType.LAZY)
	private Collection<Site> siteCollection;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "ownerId", fetch=FetchType.LAZY)
	private Collection<OwnerNick> ownerNickCollection;

	public Owner() {
	}

	public Owner(String firstName, String middleName, String lastName, Date birthDate) {
		this.firstName = firstName;
		this.middleName = middleName;
		this.lastName = lastName;
		this.birthDate = birthDate;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getMiddleName() {
		return middleName;
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public Collection<Site> getSiteCollection() {
		return siteCollection;
	}

	public void setSiteCollection(Collection<Site> siteCollection) {
		this.siteCollection = siteCollection;
	}

	public Collection<OwnerNick> getOwnerNickCollection() {
		return ownerNickCollection;
	}

	public void setOwnerNickCollection(Collection<OwnerNick> ownerNickCollection) {
		this.ownerNickCollection = ownerNickCollection;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		if (!(object instanceof Owner)) {
			return false;
		}
		Owner other = (Owner) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "pl.tom.social.dal.entity.Owner[id=" + id + "]";
	}

}
